//
//  ZYPlayerViewController.m
//  A Learning Walk
//
//  Created by 张勇 on 16/6/17.
//  Copyright © 2016年 战斗民族. All rights reserved.
//

#import "ZYPlayerViewController.h"
#import "findDetailViewController.h"
#import "CFDynamicLabel.h"
//音乐播放头文件
#import <AVFoundation/AVFoundation.h>
#import "WtyView.h"
#import "UIColor+AddColor.h"

#import "videoTableViewCell.h"

#define RADIUS 115
#define ICONWIDTH self.view.frame.size.width / 2
#define ALLANGLE 350
//宏定义   角度转弧度
#define angleToRadian(x) (x/180.0*M_PI)
@interface ZYPlayerViewController ()//<AVAudioPlayerDelegate>//签协议
@property (nonatomic,retain) CADisplayLink *link;
@property (nonatomic, retain) UIImageView *icon;//中间小圆圈
@property(nonatomic,copy)NSString *musicString;
@property(nonatomic,retain)CFDynamicLabel* ScrollLabel;//标记第几首
@property (nonatomic, assign) NSInteger angle;
@property (nonatomic, retain) WtyView *wtyView;//圆形进度条

#warning 周六修正
@property(nonatomic,retain)UIView *meter;//音量传感
@property(nonatomic,retain)UILabel *statusLabel;//状态提示

@end

@implementation ZYPlayerViewController



-(void)viewWillAppear:(BOOL)animated{
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
     if (![[defaults objectForKey:@"title"] isEqualToString:self.model.title] || [[defaults objectForKey:@"FirstTime"] isEqualToString:@"YES"]) {
    self.navigationController.navigationBar.translucent = NO;
         self.automaticallyAdjustsScrollViewInsets = NO;
        
    [self.playB setImage:[[UIImage imageNamed:@"toolbar_play_n_p"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];

        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        if ([[defaults objectForKey:@"play"] isEqualToString:@"1"]) {
            [self.playB setImage:[[UIImage imageNamed:@"toolbar_pause_n_p"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        }else{
    [self.playB setImage:[[UIImage imageNamed:@"toolbar_play_n_p"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    
    }
    [self.playB setImage:[[UIImage imageNamed:@"tabbar_np_playnon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];

         
         //创建滚动条
         self.ScrollLabel.text = nil;
         self.ScrollLabel = [[CFDynamicLabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 2 - (self.view.frame.size.width / 4) , 20, self.view.frame.size.width / 2, 40)];
         self.ScrollLabel.speed = 0.6;
         DetailListModel *model = [self.AllArray objectAtIndex:self.indexRow];
         [self.effectView addSubview:self.ScrollLabel];
         self.ScrollLabel.text = model.title;
         self.ScrollLabel.textColor = [UIColor colorWithRed:arc4random()%256 / 255.0 green:arc4random()%256 / 255.0 blue:arc4random()%256 / 255.0 alpha:1];
         self.ScrollLabel.font = [UIFont systemFontOfSize:17];
         self.ScrollLabel.backgroundColor = self.effectView.backgroundColor;
         [_ScrollLabel release];
         
         //设置背景图片和赋值
         [self setBackImage:self.indexRow];

            //得到传过来的下标
            NSInteger index = self.indexRow;
        
            //打开直接播放
            NSString *string = self.AVArray[index];
            self.musicString = string;
//            NSLog(@"%ld",(long)index);
            [self.player play:self.musicString];
            [self playMusic];
                   }
   
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.translucent = NO;
    //返回按钮
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"playingback_h"] style:UIBarButtonItemStylePlain target:self action:@selector(backAction:)];

    
    //启动过工程就把值变为NO
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:@"NO" forKey:@"FirstTime"];
    [defaults synchronize];

    //下面的初始化也可以,但设置不了enableVolumeMixer,就无法调节音量
    self.player = [[STKAudioPlayer alloc] init];
    
    self.player.volume = 0.5;
    self.player.meteringEnabled = YES;//是否启用音频测量，默认为NO，一旦启用音频测量可以通过updateMeters方法更新测量值
    //设置slider默认值
    self.progressSlider.value = 0;
    
 
    //PlayChange实现锁屏更改播放状态
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playChange:) name:@"PlayChange" object:nil];
    //监听自动切换下一曲
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(someMethod:) name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
    
    //UIApplicationDidBecomeActiveNotification
    //NSLog(@"%@",self.model);
    // Do any additional setup after loading the view from its nib.
}
//实现锁屏更改播放状态
-(void)playChange:(NSNotification *)noti{
    if ([noti.object isEqualToString:@"1"]) {
        NSLog(@"停止通知");
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:@"0" forKey:@"play"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        [self.playB setImage:[[UIImage imageNamed:@"toolbar_pause_n_p"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        [self.player resume];//继续
        [[NSNotificationCenter defaultCenter] postNotificationName:@"PlayImage" object:@"1"];

        [[videoTableViewCell sharedInstance].view removeFromSuperview];
        //往HRPlayView发送通知并携带一个字典
        DetailListModel *model =  [self.AllArray objectAtIndex:_indexRow];
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        [dic setObject:model.coverLarge forKey:@"picture"];
        [dic setObject:@"1" forKey:@"play"];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"playOrStop" object:dic];
        self.link.paused = NO;
        [[videoTableViewCell sharedInstance].player pause];
    }else{
        NSLog(@"暂停");
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:@"1" forKey:@"play"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        [self.playB setImage:[[UIImage imageNamed:@"toolbar_play_n_p"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        [self.player pause];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"PlayImage" object:@"0"];

        //往HRPlayView发送通知并携带一个字典
        DetailListModel *model =  [self.AllArray objectAtIndex:_indexRow];
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        [dic setObject:model.coverLarge forKey:@"picture"];
        [dic setObject:@"0" forKey:@"play"];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"playOrStop" object:dic];
        self.link.paused = YES;
    
    }
    


}
//设置背景图片和赋值
-(void)setBackImage:(NSInteger)indexPath{
   
    //设置button的背景图片
    [self.playListB setImage:[[UIImage imageNamed:@"toolbar_playinglist_n_p"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [self.backB setImage:[[[UIImage imageNamed:@"toolbar_prev_n_p"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    
    [self.goB setImage:[[UIImage imageNamed:@"toolbar_next_n_p"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [self.timingB setImage:[[UIImage imageNamed:@"toolbar_clock_n_p"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    
    //赋值
    DetailListModel *model = [self.AllArray objectAtIndex:self.indexRow];
    self.userImageV.layer.masksToBounds = YES;
    self.userImageV.layer.cornerRadius = self.userImageV.frame.size.width / 2;
    [self.userImageV sd_setImageWithURL:[NSURL URLWithString:model.smallLogo] placeholderImage:[UIImage imageNamed:@"holderr"]];
    self.userL.text = model.nickname;
    self.userL.font = [UIFont systemFontOfSize:15];
    [self.BGImageV sd_setImageWithURL:[NSURL URLWithString:model.coverLarge] placeholderImage:[UIImage imageNamed:@"hold"]];
    
    self.timeTotleL.textColor = [UIColor orangeColor];
    if (model.duration.integerValue % 60 < 10) {
        self.timeTotleL.text = [NSString stringWithFormat:@"%d:%d",model.duration.integerValue / 60 , model.duration.integerValue % 60 * 10];
        self.timeTotleL.font = [UIFont systemFontOfSize:10];
    }else{
        self.timeTotleL.text = [NSString stringWithFormat:@"%d:%d",model.duration.integerValue / 60 , model.duration.integerValue % 60 ];
        self.timeTotleL.font = [UIFont systemFontOfSize:10];
        
    }
    
     //创建中间圆形
    if (self.icon == nil) {
        self.icon = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ICONWIDTH, ICONWIDTH)];
        self.icon.center = self.BGImageV.center;
        self.icon.layer.cornerRadius = ICONWIDTH / 2;
        self.icon.layer.borderWidth = 3;
        self.icon.layer.borderColor = [[UIColor colorFromHexCode:@"#ffffff"] CGColor];
        self.icon.clipsToBounds = YES;
        [self.view addSubview:self.icon];
        [_icon release];
        // 启动定时器        
       // [self startAnimation];
    }
   
    [self.icon sd_setImageWithURL:[NSURL URLWithString:model.coverLarge] placeholderImage:[UIImage imageNamed:@"hold"]];

    //改变滚动标题名
    self.ScrollLabel.text = model.title;
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[NSString stringWithFormat:@"%@",model.title] forKey:@"title"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    self.ScrollLabel.textColor = [UIColor colorWithRed:arc4random()%256 / 255.0 green:arc4random()%256 / 255.0 blue:arc4random()%256 / 255.0 alpha:1];
    
#warning 周六修正
    //音量跳动条 和 缓冲
    
    self.meter = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
    //self.meter.backgroundColor = [UIColor colorFromHexCode:@"#COFF3E"];
    [self.view bringSubviewToFront:self.meter];
    [self.BGImageV addSubview:self.meter];
    //self.meter.backgroundColor = [UIColor clearColor];
    self.statusLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width - 100, 25, 100, 20)];
    self.statusLabel.textAlignment = NSTextAlignmentCenter;
    self.statusLabel.backgroundColor = [UIColor clearColor];
    [self.view addSubview:self.statusLabel];
    [_meter release];
    [_statusLabel release];


}
#pragma mark - 创建进度条视图（WTYView)
- (void)createWtyViewWithCurrentTime:(int)currentTime durationTime:(int)durantionTime
{
    self.wtyView = [[WtyView alloc] initWithFrame:CGRectMake(0, 0, RADIUS * 2 + 15, RADIUS * 2 + 15)];
    self.wtyView.center = self.icon.center;
    self.wtyView.backgroundColor = [UIColor clearColor];
    self.wtyView.currentTime = currentTime;
    self.wtyView.durationTime = durantionTime;
    self.wtyView.radius = RADIUS;
    [_wtyView release];
    [self.view addSubview:self.wtyView];
}


//设置slider和播放时间相等
-(void)timerAction{
    //设置slider等于当前时间
    self.progressSlider.value = self.player.progress;
    NSLog(@"计时器");
}
//进度条
- (IBAction)progressSlider:(id)sender {
    if (self.player) {
        [self.player seekToTime:self.progressSlider.value];
    }
    NSLog(@"进度条");
}

//下一曲
- (IBAction)GoButton:(UIButton *)sender {
    //在开始播放之前，禁用一切的app点击事件
    UIWindow *window=[[UIApplication sharedApplication].windows lastObject];
    window.userInteractionEnabled=NO;
    NSLog(@"下一曲");
    //+1后对总数取余是为了防止点击多次,数组越界
    self.indexRow++;
 
    if (self.indexRow > self.AllArray.count - 1) {
        self.indexRow = 0;
        DetailListModel *model =  [self.AllArray objectAtIndex:_indexRow];
        NSString *string = model.playUrl64;
        //把model存起来以备第一次启动用
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:model.coverLarge forKey:@"model"];
//        [defaults setObject:[NSArray arrayWithArray:self.AllArray] forKey:@"allArray"];
        [defaults synchronize];
        
        [self.player play:string];
        [self playMusic];
        //设置背景图片和赋值
        [self setBackImage:self.indexRow];
        [self.wtyView removeFromSuperview];
        [self createWtyViewWithCurrentTime:0 durationTime:1];
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        [dic setObject:model.coverLarge forKey:@"picture"];
        [dic setObject:@"1" forKey:@"play"];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"playOrStop" object:dic];
        
    }else{
        NSString *string = [self.AVArray objectAtIndex:self.indexRow];
        [self.player play:string];
        [self playMusic];
        //设置背景图片和赋值
        [self setBackImage:self.indexRow];
        [self.wtyView removeFromSuperview];
        [self createWtyViewWithCurrentTime:0 durationTime:1];
        
        
    }

    //回复window的点击为可用
    window.userInteractionEnabled=YES;
    
}
//自动下一曲
-(void)someMethod:(NSNotification *)noti{
    //在开始播放之前，禁用一切的app点击事件
//    UIWindow *window=[[UIApplication sharedApplication].windows lastObject];
//    window.userInteractionEnabled=NO;
    NSLog(@"自动下一曲");
    //+1后对总数取余是为了防止点击多次,数组越界
    self.indexRow++;
    
    if (self.indexRow > self.AllArray.count - 1) {
        self.indexRow = 0;
        DetailListModel *model =  [self.AllArray objectAtIndex:_indexRow];
        NSString *string = model.playUrl64;
        //把model存起来以备第一次启动用
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:model.coverLarge forKey:@"model"];
        //        [defaults setObject:[NSArray arrayWithArray:self.AllArray] forKey:@"allArray"];
        [defaults synchronize];
        
        [self.player play:string];
        [self playMusic];
        //设置背景图片和赋值
        [self setBackImage:self.indexRow];
        [self.wtyView removeFromSuperview];
        [self createWtyViewWithCurrentTime:0 durationTime:1];
        
        
    }else{
        NSString *string = [self.AVArray objectAtIndex:self.indexRow];
        [self.player play:string];
        [self playMusic];
        //设置背景图片和赋值
        [self setBackImage:self.indexRow];
        [self.wtyView removeFromSuperview];
        [self createWtyViewWithCurrentTime:0 durationTime:1];
        
        
    }
    
    //回复window的点击为可用
    //window.userInteractionEnabled=YES;
}

//播放列表
- (IBAction)playListB:(UIButton *)sender {
    
}
////上一曲
- (IBAction)backB:(UIButton *)sender {
    //在开始播放之前，禁用一切的app点击事件
    UIWindow *window=[[UIApplication sharedApplication].windows lastObject];
    window.userInteractionEnabled=NO;
        self.indexRow--;
        if (self.indexRow < 0) {
            self.indexRow = self.AllArray.count - 1;
            DetailListModel *model =  [self.AllArray objectAtIndex:_indexRow];
            NSString *string = model.playUrl64;
            
            //把model存起来以备第一次启动用
           NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
            [defaults setObject:model.coverLarge forKey:@"model"];
//              [defaults setObject:[NSArray arrayWithArray:self.AllArray] forKey:@"allArray"];
            [defaults synchronize];
            [self.player play:string];
            [self playMusic];
            //设置背景图片和赋值
            [self setBackImage:self.AVArray.count - 1];
            [self.wtyView removeFromSuperview];
            [self createWtyViewWithCurrentTime:0 durationTime:1];
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            [dic setObject:model.coverLarge forKey:@"picture"];
            [dic setObject:@"1" forKey:@"play"];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"playOrStop" object:dic];
        
        }else{
            DetailListModel *model =  [self.AllArray objectAtIndex:_indexRow];
            NSString *string = model.playUrl64;
            [self.player play:string];
            [self playMusic];
            //设置背景图片和赋值
            [self setBackImage:self.indexRow];
            [self.wtyView removeFromSuperview];
            [self createWtyViewWithCurrentTime:0 durationTime:1];
            
        }
    NSLog(@"上一曲");
    //回复window的点击为可用
    window.userInteractionEnabled=YES;
}
//播放按钮
- (IBAction)playB:(UIButton *)sender {
    
    NSLog(@"222222%d", self.player.state);
    
    if (self.player.progress != 0) {
        
  
    if (self.player.state == STKAudioPlayerStatePaused) {
        
        NSLog(@"播放");
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:@"0" forKey:@"play"];
         [[NSUserDefaults standardUserDefaults] synchronize];
        [self.playB setImage:[[UIImage imageNamed:@"toolbar_pause_n_p"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        [self.player resume];//继续
        [[NSNotificationCenter defaultCenter] postNotificationName:@"PlayImage" object:@"1"];
#warning ++++++++++++
       // [[NSNotificationCenter defaultCenter] postNotificationName:@"bool" object:@"1"];
#warning ++++++++++++
        [[videoTableViewCell sharedInstance].view removeFromSuperview];
        //往HRPlayView发送通知并携带一个字典
        DetailListModel *model =  [self.AllArray objectAtIndex:_indexRow];
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        [dic setObject:model.coverLarge forKey:@"picture"];
        [dic setObject:@"1" forKey:@"play"];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"playOrStop" object:dic];
        self.link.paused = NO;
        [[videoTableViewCell sharedInstance].player pause];
        
    }else if (self.player.state == STKAudioPlayerStatePlaying) {
        
        NSLog(@"暂停");
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:@"1" forKey:@"play"];
         [[NSUserDefaults standardUserDefaults] synchronize];
        [self.playB setImage:[[UIImage imageNamed:@"toolbar_play_n_p"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        [self.player pause];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"PlayImage" object:@"0"];
#warning ++++++++++++
//        NSMutableDictionary *bolldic = [NSMutableDictionary dictionary];
//        [bolldic setObject:self.AllArray forKey:@"array"];
//        [bolldic setObject:[NSString stringWithFormat:@"%ld",(long)_indexRow]  forKey:@"index"];
//        [[NSNotificationCenter defaultCenter] postNotificationName:@"bool" object:self.AllArray];
#warning ++++++++++++
        //往HRPlayView发送通知并携带一个字典
        DetailListModel *model =  [self.AllArray objectAtIndex:_indexRow];
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
         [dic setObject:model.coverLarge forKey:@"picture"];
        [dic setObject:@"0" forKey:@"play"];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"playOrStop" object:dic];
        //暂停滚动
        self.link.paused = YES;
        
        
    }else
    {
        NSLog(@"继续播吧");
        [self.player play:self.musicString];
        [self playMusic];
        [self ButtonPlay];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"PlayImage" object:@"1"];
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:@"0" forKey:@"play"];
        [[NSUserDefaults standardUserDefaults] synchronize];
       self.link.paused = NO;
    }
      }
}
//播放状态
-(void)ButtonPlay{

[self.playB setImage:[[UIImage imageNamed:@"toolbar_pause_n_p"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];

}
//播放音乐
- (void)playMusic
{
    
    self.meter.frame = CGRectMake(0, 0, 0, 0);
    //把model存起来以备第一次启动用
     DetailListModel *model =  [self.AllArray objectAtIndex:_indexRow];
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:model.coverLarge forKey:@"model"];
//     [defaults setObject:[NSArray arrayWithArray:self.AllArray] forKey:@"allArray"];
    [defaults synchronize];
    [[videoTableViewCell sharedInstance].player pause];
    [self ButtonPlay];
    self.timer = [NSTimer scheduledTimerWithTimeInterval:0.f target:self selector:@selector(track) userInfo:nil repeats:YES];
    self.link.paused = NO;
#warning ++++++++++++
    // [[NSNotificationCenter defaultCenter] postNotificationName:@"bool" object:@"1"];
#warning ++++++++++++    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setObject:model.coverLarge forKey:@"picture"];
    [dic setObject:@"1" forKey:@"play"];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"playOrStop" object:dic];
   
    [defaults setObject:@"YES" forKey:@"FirstPlay"];
    [defaults synchronize];
    //播放开始就指空
    self.statusLabel.text = @"";
}
-(void)track

{
   // NSLog(@"====%@",self.player);
    
    self.progressSlider.maximumValue = self.player.duration;//音乐总共时长
    self.progressSlider.value = self.player.progress;//当前进度
    
    //当前时长progress
    NSInteger proMin = (NSInteger)self.player.progress / 60;//当前秒
    NSInteger proSec = (NSInteger)self.player.progress % 60;//当前分钟
    
    //先移除前一秒的view
    [self.wtyView removeFromSuperview];
    [self createWtyViewWithCurrentTime:self.player.progress durationTime:self.player.duration];
    
    self.timeNowL.text = [NSString stringWithFormat:@"%02ld:%02ld", (long)proMin, (long)proSec];
    self.timeNowL.font = [UIFont systemFontOfSize:10];
    self.timeNowL.textColor = [UIColor orangeColor];
    // NSLog(@"proMin = %ld proSec = %ld",proMin, proSec);
    
#warning 周六修正
    
    self.statusLabel.text = self.player.state == STKAudioPlayerStateBuffering ? @"正在缓冲···" : @"";
    self.meter.backgroundColor = [UIColor clearColor];
    
    CGFloat newWidth = 320 * (([self.player averagePowerInDecibelsForChannel:1] + 60) / 60);
    
    self.meter.frame = CGRectMake(0, self.BGImageV.frame.size.height - 30, self.view.frame.size.width, -newWidth);
    if (newWidth > self.view.frame.size.width / 3) {
        self.meter.backgroundColor = [UIColor colorFromHexCode:@"#76BECC"];
    }else if(newWidth > self.view.frame.size.width / 2){
        
        self.meter.backgroundColor = [UIColor colorFromHexCode:@"#78CDD1"];
    }else if (newWidth > self.view.frame.size.width / 4 * 3){
        
        self.meter.backgroundColor = [UIColor colorFromHexCode:@"#00AE9B"];
    
    }
    
}

//开始转动
//- (void)startAnimation
//{
//    
//    __block ZYPlayerViewController *play = self;
//    [UIView animateWithDuration:5 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
//        play.icon.transform = CGAffineTransformMakeRotation(play.angle);
//    } completion:^(BOOL finished) {
//        play.angle += 90;
//        [play startAnimation];
//        
//    }];
//    
//}

//无线循环
- (CADisplayLink *)link {
    if (!_link) {
        // 创建定时器, 一秒钟调用rotation方法60次
        _link = [CADisplayLink displayLinkWithTarget:self selector:@selector(rotation)];
        // 手动将定时器加入到事件循环中
        [_link addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    }
    return _link;
}

//无线循环
- (void)rotation {
    self.icon.layer.transform = CATransform3DRotate(self.icon.layer.transform, angleToRadian(72/60.0), 0, 0, 1);
}

//计时器
- (IBAction)timingB:(UIButton *)sender {
    
}

//返回按钮
-(void)backAction:(UIBarButtonItem *)bar{

[self dismissViewControllerAnimated:YES completion:^{
    
    
}];
  
}




+(instancetype)shareZYPlayerViewController
{
    
    static ZYPlayerViewController *player = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        player = [[ZYPlayerViewController alloc] init];
        
    });
    
    return player;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(void)viewWillDisappear:(BOOL)animated{
//移除音量的显示label
  [self.meter removeFromSuperview];
    NSLog(@"小时");
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)dealloc {
    [_userImageV release];
    [_userL release];
    [_BGImageV release];
    [_timeNowL release];
    [_timeTotleL release];
    [_playListB release];
    [_backB release];
    [_playB release];
    [_goB release];
    [_timingB release];
    [_AVArray release];
    [_ScrollLabel release];
    [_effectView release];
    [_icon release];
    [_wtyView release];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"PlayChange" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [super dealloc];
}



@end
